package org.algorithm.落雪.链表;

import org.algorithm.biubiu.wheel_1.common.ListNode;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date 2022/2/25
 * @Link {https://leetcode-cn.com/problems/next-greater-node-in-linked-list/}
 */
public class 链表中下一个最大的节点 {


    @Test
    public  void  test(){
        int[] ints = nextLargerNodes(ListNode.build(1, 7, 5, 1, 9, 2, 5, 1));
        System.out.println("ints = " + ints);
    }

    public int[] nextLargerNodes(ListNode head) {

        List<Integer> list = new ArrayList<Integer>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        int[] res = new int[list.size()];
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = i + 1; j < list.size(); j++) {
                if(list.get(j)>list.get(i)){
                    res[i]=list.get(j);
                    break;
                }
            }
        }
        return res;

    }
}
